﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CLEXA.DataContracts;
using CLEXA.ServiceContracts;

namespace CLEXA.SurfaceClient.Functions
{
    public class Schema : ISchema
    {
        private readonly INavigator navigator;
        private readonly IClientService clientService;
        private readonly UserData user;
        private readonly DatabaseData database;
        private readonly List<TableData> tables;
        private readonly ReadOnlyCollection<TableData> tablesReadOnly;

        public DatabaseData Database
        {
            get { return database; }
        }

        public ReadOnlyCollection<TableData> Tables
        {
            get { return tablesReadOnly; }
        }

        public Schema(INavigator navigator, IClientService clientService, UserData user, DatabaseData database)
        {
            this.navigator = navigator;
            this.clientService = clientService;
            this.user = user;
            this.database = database;
            this.tables = clientService.GetSchema(database.ConnectionString);
            this.tablesReadOnly = new ReadOnlyCollection<TableData>(this.tables);
        }

        public void GoToHome()
        {
            navigator.GoToHome(user);
        }
    }
}
